package com.bootdo.common.configure.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bootdo.common.annotation.Log;
import com.bootdo.common.utils.google.GoogleAuthenticator;

/**
 * @Desc 谷歌验证码校验
 * @date 2019/11/13
 *
 */
@RestController
@RequestMapping("/google")
public class GoogleController extends BaseController {

    @Log("谷歌验证码校验")
    @PostMapping("/check")
    boolean check(String code){
        if (1 == getUserId()){
            return true;
        } else {
            return GoogleAuthenticator.checkCode(getUser().getSecret(), code);
        }
    }

    @Log("谷歌验证码登录校验")
    @PostMapping("/login")
    boolean login(String code, String secret){
        return GoogleAuthenticator.checkCode(secret, code);
    }
}
